package com.example.myworkers.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.myworkers.model.Emp;
import com.example.myworkers.service.EmpService;
import com.example.myworkers.dao.EmpMapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;



/**
 *
 */
@Service
public class EmpServiceImpl extends ServiceImpl<EmpMapper, Emp>
    implements EmpService {

    @Autowired
    private EmpMapper empMapper;

    @Override
    public String login(HttpServletRequest request,Emp emp) {

//        String ip = GetIpUtils.getRequesterIP(request);

        LambdaQueryWrapper<Emp> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(emp.getEmpname()),Emp::getEmpname,emp.getEmpname())
                .eq(StringUtils.isNotBlank(emp.getEmppassword()),Emp::getEmppassword,emp.getEmppassword());

        Emp one = empMapper.selectOne(queryWrapper);

        if (Objects.nonNull(one)) {
            return "login success";
        }

        return "username or password error";
    }
}




